import { unlink } from 'fs/promises';
import { join } from 'path';
import { revalidateTag } from 'next/cache';
import { NextResponse } from 'next/server';

export const dynamic = 'force-dynamic';

// 删除文件接口
export async function DELETE(request: Request, { params }: { params: { slug: string[] } }) {
    try {
        //文件根目录
        const rootPath = join(process.cwd(), process.env.FILE_LOCATION || '/');
        await unlink(join(rootPath, ...params.slug));
        revalidateTag('mirrors');
        return NextResponse.json({
            status: 1,
            msg: '删除成功',
            data: null,
        });
    } catch (error) {
        return NextResponse.json({
            status: 0,
            msg: '删除失败',
            data: null,
        });
    }
}
